/********************************************************************
***	Author : Franck Tomeba - Domenico DE FANO
*** 	Coprocessor Simulation 1
***	Do 1 monitoring round
***	Read and print the results stored in the result buffer
***
********************************************************************/
#include "TestApp.h"
#include "stdio.h"

int main(void)
{
	unsigned int value;

	print("\n\rCoprocessor Simulation 1\n\r");
	print("Do 1 monitoring round and result 4 result buffer registers\n\r");
	
	enable_interrupt();
	
	print("Set Monitoring Length : 0x1B\n\r");
	write_reg(OFFSET_MON_LEN, 0x0000001B);

	print("Set Scan Period : 0x3B\n\r");
	write_reg(OFFSET_SCAN_PERIOD, 0x0000003B);
	
	print("Set Configuration Buffer : 0x05\n\r");
	write_reg(OFFSET_GW_CONFIG, 0x00000005);
	
	print("Start Monitoring\n\r");
	write_reg(OFFSET_CMD, CMD_START);
	write_reg(OFFSET_CMD, CMD_NOP);
	
	print("Busy Waiting on Interrupt\n\r");
	value = 0;
	do {
		value = read_reg(OFFSET_IRQ);
		print("\n\rIRQ Reg :");
		putnum(value);
	} while ( value == 0 );

	//do {
		print("Read Monitoring Values\n\r");
		
		value = read_reg(OFFSET_STATUS);
		print("\n\rSTATUS : ");
		putnum(value);
		
		value = read_reg(OFFSET_RESULT_BUFFER_1);
		print("\n\rResult Buffer 1 : ");
		putnum(value); 
		
		value = read_reg(OFFSET_RESULT_BUFFER_2);
		print("\n\rResult Buffer 2 : ");
		putnum(value); 
		
		value = read_reg(OFFSET_RESULT_BUFFER_3);
		print("\n\rResult Buffer 3 : ");
		putnum(value); 
	
		value = read_reg(OFFSET_RESULT_BUFFER_4);
		print("\n\rResult Buffer 4 : ");
		putnum(value); 
		
		//value = read_reg(OFFSET_IRQ);
	//} while (0 == 0);
	print("\n\rStop Monitoring\n\r");
	write_reg(OFFSET_CMD, CMD_STOP);
	write_reg(OFFSET_CMD, CMD_NOP);
	
	enable_interrupt();
	

	
	return 1;
}
